package m.app.action;

import m.base.util.PowerUtil;
import m.common.action.ActionMeta;
import m.common.action.RequestMeta;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import m.common.model.util.QueryOrder;
import m.fun.model.GoodsOffer;
import m.store.model.StoreGoods;
import m.store.model.StoreType;
import m.system.document.DocumentMeta;
import m.system.document.DocumentMethodMeta;
import m.system.document.DocumentParamMeta;
import m.system.lang.HtmlBodyContent;
import m.system.util.JSONMessage;
import m.system.util.StringUtil;
import manage.model.StatusModel;

@ActionMeta(name = "app/storeGoods",title = "app商品信息")
public class StoreGoodsAction extends AppAction{
    @DocumentMeta(
        method = @DocumentMethodMeta(title = "商品查询列表",permission = true),
        params = {
            @DocumentParamMeta(name = "page.index",description = "分页开始位置",type = FieldType.INT),
            @DocumentParamMeta(name = "page.num",description = "分页每页数量",type = FieldType.INT),
            @DocumentParamMeta(name = "params[userNoOffer]",description = "用户未报价",type = FieldType.STRING,dictOption = "Y:未报价,N:全部"),
            @DocumentParamMeta(name = "params[oid@eq]",description = "条件示例，字段和操作符中间用@，值为空不添加",type = FieldType.STRING,length = 50),
            @DocumentParamMeta(name = "params[oid#desc]",description = "排序示例，字段和操作符中间用#，值为空不生效",type = FieldType.STRING,length = 50)
        }
    )
    public JSONMessage queryList() throws Exception {
        ModelQueryList queryList=toQueryList(StoreGoods.class,"*","storeType.name");
        queryList.addCondition(QueryCondition.eq("store.oid", PowerUtil.getSessionStoreOid()));
        if("Y".equals(StringUtil.noSpace(getParamsValue("userNoOffer")))){
            queryList.addCondition(QueryCondition.notEmpty("storeType.oid"));
            queryList.addCondition(QueryCondition.not(
                QueryCondition.in("oid",
                    ModelQueryList.instance(GoodsOffer.class,new String[]{"goods.oid"},null,
                        QueryCondition.eq("user.oid",PowerUtil.getSessionUserOid())
                    )
                )
            ));
        }
        return JSONMessage.success("查询成功")
                .push("page",ModelQueryList.getModelPageInfo(queryList));
    }
    @DocumentMeta(
        method = @DocumentMethodMeta(title = "查询商品信息",permission = true),
        params = {
            @DocumentParamMeta(name = "oid",description = "商品oid",type = FieldType.STRING,length = 50)
        }
    )
    @RequestMeta(params = {"oid"})
    public JSONMessage queryInfo(String oid) throws Exception {
        StoreGoods model=ModelQueryList.getModel(StoreGoods.class,oid,"*","storeType.name");
        return JSONMessage.success("查询成功")
                .push("model",model);
    }

}
